3 var byteLength
= require( 'mediawiki.String' ).byteLength
,
4 codePointLength
= require( 'mediawiki.String' ).codePointLength
;
11 * Add a visible byte limit label to a TextInputWidget.
13 * Uses jQuery#byteLimit to enforce the limit.
15 * @param {OO.ui.TextInputWidget} textInputWidget Text input widget
16 * @param {number} [limit] Byte limit, defaults to $input's maxlength
18 mw
.widgets
.visibleByteLimit = function ( textInputWidget
, limit
) {
19 limit
= limit
|| +textInputWidget
.$input
.attr( 'maxlength' );
21 function updateCount() {
22 var remaining
= limit
- byteLength( textInputWidget
.getValue() );
23 if ( remaining
> 99 ) {
26 remaining
= mw
.language
.convertNumber( remaining
);
28 textInputWidget
.setLabel( remaining
);
30 textInputWidget
.on( 'change', updateCount
);
34 // Actually enforce limit
35 textInputWidget
.$input
.byteLimit( limit
);
39 * Add a visible codepoint (character) limit label to a TextInputWidget.
41 * Uses jQuery#codePointLimit to enforce the limit.
43 * @param {OO.ui.TextInputWidget} textInputWidget Text input widget
44 * @param {number} [limit] Byte limit, defaults to $input's maxlength
46 mw
.widgets
.visibleCodePointLimit = function ( textInputWidget
, limit
) {
47 limit
= limit
|| +textInputWidget
.$input
.attr( 'maxlength' );
49 function updateCount() {
50 var remaining
= limit
- codePointLength( textInputWidget
.getValue() );
51 if ( remaining
> 99 ) {
54 remaining
= mw
.language
.convertNumber( remaining
);
56 textInputWidget
.setLabel( remaining
);
58 textInputWidget
.on( 'change', updateCount
);
62 // Actually enforce limit
63 textInputWidget
.$input
.codePointLimit( limit
);